package com.heboan.www;



/*
    提示用户输入年月日信息，判断是这一年中的第几天并打印
*/
import java.util.Scanner;

public class Demo01 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int year = 0;
        int month = 0;
        int day = 0;

        // 接收 年
        do {
            System.out.print("请输入年:");
            year = sc.nextInt();
        } while (year < 0);

        // 接收 月

        do {
            System.out.println("请输入月[1-12]");
            month = sc.nextInt();
        } while (month <= 0 || month > 12);


        // 计算该月的总天数
        int currentMonthDays;
        if (month == 2) {
            if (year%4==0&&year%100!=0||year%400==0) {
                currentMonthDays = 29;
            } else {
                currentMonthDays = 28;
            }
        } else if (month==1||month==3||month==5||month==7||month==8||month==10||month==12) {
            currentMonthDays = 31;
        } else {
            currentMonthDays = 30;
        }


        // 接收 日
        while (true) {
            String msg = "请输入日[1-" + currentMonthDays + "]";
            System.out.println(msg);
            day = sc.nextInt();

            if (day>=1 && day <= currentMonthDays){
                break;
            }

        }


        int sumDays = day;

        if (month >1){
            int[] dayList = new int[month-1];
            // 获取 每个月的天数放入数组
            for (int i=1; i<=dayList.length; i++) {

                if (i==1||i==3||i==5||i==7||i==8||i==10){
                    dayList[i-1] = 31;
                } else if(i==2){
                    if (year%4==0&&year%100!=0||year%400==0) {
                        dayList[i-1] = 29;
                    } else {
                        dayList[i-1] = 28;
                    }
                } else {
                    dayList[i-1] = 30;
                }
            }
            // 把月份天数加起来
            for (int i=0; i<dayList.length;i++){
                sumDays += dayList[i];
            }
        }

        System.out.println(year + "年" + month + "月" + day + "日是这一年的第" + sumDays + "天"  );
    }
}
